package com.example.auth.common.base;

/**
 * <p>
 *
 * </p>
 *
 * @author Yi
 * @version V1.0
 * @date 2019/1/13 21:25
 * @modificationHistory=========================逻辑或功能性重大变更记录
 * @modify By: {修改人} 2019/1/13
 * @modify reason: {方法名}:{原因}
 * ...
 */
public enum ApiErrorCode implements IErrorCode {
    /**
     * 失败
     */
    FAILED("0", "失败"),
    /**
     * 成功
     */
    SUCCESS("1", "成功");

    private final String code;
    private final String msg;

    ApiErrorCode(final String code, final String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static ApiErrorCode fromCode(String code) {
        ApiErrorCode[] ecs = ApiErrorCode.values();
        for (ApiErrorCode ec : ecs) {
            if (ec.getCode().equalsIgnoreCase(code)) {
                return ec;
            }
        }
        return SUCCESS;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getMsg() {
        return msg;
    }

    @Override
    public String toString() {
        return String.format(" ErrorCode:{code=%s, msg=%s} ", code, msg);
    }
}
